<template>
    <div class="bigbox">
        <!-- 使用 flex 布局，让 box 在左边，二维码容器在右边 -->
        <div class="layout">
            <!-- box内容 -->
            <div class="box">
                <!-- 静态筛选栏 -->
                <div class="static-filter-bar">
                    <div class="static-check-group">
                        <label class="locked-checkbox">
                            <input type="checkbox" disabled>
                            <span class="custom-checkbox"></span>
                            <span class="label-text">有囤购</span>
                        </label>
                        <label class="locked-checkbox">
                            <input type="checkbox" disabled>
                            <span class="custom-checkbox"></span>
                            <span class="label-text">可订座</span>
                        </label>
                    </div>

                    <div class="static-sorts">
                        <span class="sort-item">智能</span>
                        <span class="separator">|</span>
                        <span class="sort-item">好评↓</span>
                        <span class="separator">|</span>
                        <span class="sort-item">人气↓</span>
                        <span class="separator">|</span>
                        <span class="sort-item">评价最多↓</span>
                        <span class="separator">|</span>
                        <span class="sort-item">人均...</span>
                    </div>
                </div>

                <div v-if="loading" class="loading">加载中...</div>
                <div v-else-if="!Huanglist2.length" class="empty">暂无数据</div>
                <div v-else class="container">
                    <div 
                        class="item" 
                        v-for="item in Huanglist2" 
                        :key="item.id" 
                        @click="goToDetail(item.id)"
                    >
                        <div class="item-left">
                            <img 
                                :src="item.additional_info" 
                                alt="商品图片" 
                                class="item-image"
                            >
                        </div>
                        <div class="item-right">
                            <h3 class="item-title">{{ item.name }}</h3>
                            <div class="item-rating">
                                <span class="rating-value">{{ item.rating }}</span>
                                <span class="reviews">({{ item.reviews }}条评价)</span>
                            </div>
                            <div class="item-price">人均 ¥{{ item.price_per_person }}</div>
                            <div class="item-categories">
                                <span v-for="(category, index) in item.categories" :key="index">
                                    {{ category }}<span v-if="index < item.categories.length - 1"> | </span>
                                </span>
                            </div>
                        </div>
                    </div>
                </div>
                <div v-if="error" class="error">数据加载失败: {{ error }}</div>
            </div>

            <!-- 二维码容器，右侧 -->
            <div class="qr-code-container">
                <img src="@/assets/images/erweima.png" alt="二维码图片" class="qr-code-image">
            </div>
        </div>
    </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import axios from 'axios'
import { useRouter } from 'vue-router'

const router = useRouter()
const Huanglist2 = ref([])
const loading = ref(true)
const error = ref(null)

const fetchData = async () => {
    try {
        const response = await axios.get('/Huanglist2')
        Huanglist2.value = response.data || []
    } catch (err) {
        console.error('请求失败:', err)
        error.value = err.message
    } finally {
        loading.value = false
    }
}

const goToDetail = (id) => {
    router.push(`/Huangdetail2/${id}`)
}

onMounted(() => {
    fetchData()
})
</script>

<style scoped>
/* 使用 flex 布局，让 box 在左边，二维码容器在右边 */
.bigbox {
    max-width: 1200px;
    margin: 0 auto; /* 居中整体内容 */
}

.layout {
    display: flex;
    justify-content: space-between; /* box在左，二维码在右 */
    align-items: flex-start;
    margin-left: -20px; /* 使左侧盒子稍微向左移动 */
}

/* box 容器样式不变 */
.box {
    max-width: 980px;
    width: 100%;
    background-color: #fff; /* 设置外容器背景为白色 */
    margin-left: 10px; /* 左侧边距增加一点 */
}

/* 二维码容器 */
.qr-code-container {
    top: 0px;  /* 修改为0，确保与上边框对齐 */
    right: 10px; 
    margin-right: 20px;
    flex-shrink: 0; /* 防止二维码容器缩小 */
    max-width: 240px; /* 限制二维码容器最大宽度 */
   
}

.qr-code-image {
    width: 100%; 
    height: auto;
    margin-left: 26px;
     border: #e0e0e0 1px solid;
}

/* 筛选栏容器 */
.static-filter-bar {
    width: 920px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    background: #fff;
    border: 1px solid #e0e0e0;
    margin-bottom: 10px;
}

/* 复选框组样式 */
.static-check-group {
    display: flex;
    gap: 20px;
    align-items: center;
}

/* 禁用交互效果 */
.locked-checkbox {
    display: flex;
    align-items: center;
    cursor: not-allowed;
}

/* 隐藏原生复选框 */
.locked-checkbox input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

/* 自定义灰色复选框 */
.custom-checkbox {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 1px solid #999;
    border-radius: 3px;
    margin-right: 6px;
    background: #f5f5f5;
    position: relative;
}

/* 选中状态 */
.locked-checkbox input:checked + .custom-checkbox {
    background: #d9d9d9;
    border-color: #666;
}

/* 选中图标 */
.locked-checkbox input:checked + .custom-checkbox::after {
    content: "";
    position: absolute;
    left: 3px;
    top: 0;
    width: 4px;
    height: 8px;
    border: solid #666;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

/* 文字样式 */
.label-text {
    font-size: 13px;
    color: #666;
}

/* 右侧排序样式 */
.static-sorts {
    display: flex;
    align-items: center;
    gap: 8px;
}

.sort-item {
    font-size: 13px;
    color: #666;
    cursor: default;
}

/* 新增：默认智能项橙色 */
.static-sorts .sort-item:first-child {
    color: #ff6000;
}

/* 新增：悬停效果 */
.static-sorts .sort-item:hover {
    color: #ff6000;
}

.separator {
    color: #d9d9d9;
    user-select: none;
}

/* 原有列表样式保持不变 */
.container {
    width: 920px;
    margin: 0 auto;
    padding: 15px;
    border: 1px solid #e0e0e0;
}

.item {
    display: flex;
    padding: 15px 0;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    background-color: #fff; /* 设置默认背景为白色 */
    transition: background 0.3s;
}

.item:hover {
    background: #f8f8f8;
}

.item-left {
    margin-right: 20px; /* 调整间距为20px */
}

.item-image {
    width: 100px;
    height: 75px;
    border-radius: 4px;
    object-fit: cover;
    background: #eee;
}

.item-right {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between; /* 使价格部分与图片底部对齐 */
}

.item-title {
    font-size: 16px;
    font-weight: bold;
    margin: 0 0 8px 0;
    color: #333;
}

.item-rating {
    margin-bottom: 8px;
}

.rating-value {
    color: #ff6000;
    font-weight: bold;
    margin-right: 5px;
}

.reviews {
    color: #999;
    font-size: 12px;
}

.item-price {
    color: #666;
    font-size: 14px;
    margin-bottom: 8px;
    margin-top: 20px; /* 增加与上方内容的间距 */
}

.item-categories {
    color: #999;
    font-size: 12px;
}

.loading, .empty, .error {
    padding: 20px;
    text-align: center;
    color: #666;
}

.error {
    color: #ff4444;
}
</style>
